package psn.qiuyiping.autocad.dxffile;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class DxfFile {
    final Map<String, List<DxfClassDef>> apps;
    String                               currentSection = null;
    final Map<String, DxfDimStyle>       dimStyles;
    final Map<String, Object>            headerSetting;
    final Map<String, DxfLayer>          layers;
    final Map<String, DxfLType>          ltypes;
    final Map<Long, Object>              objects;
    final Map<String, DxfTextStyle>      textStyles;

    public DxfFile() {
        this.headerSetting = new java.util.TreeMap<>();
        this.apps = new java.util.TreeMap<>();
        this.objects = new java.util.TreeMap<>();
        this.layers = new java.util.TreeMap<>();
        this.ltypes = new java.util.TreeMap<>();
        DxfLType Continuous = new DxfLType();
        Continuous.name = "Continuous";
        ltypes.put("Continuous", Continuous);
        this.textStyles = new java.util.TreeMap<>();
        this.dimStyles = new java.util.TreeMap<>();
    }

    public void addObject(DxfHandle handle, Object obj) {
        objects.put(handle.handle, obj);
    }

    public DxfDimStyle getDimStyle(String name) {
        DxfDimStyle dimStyle = dimStyles.get(name);
        if (dimStyle == null) {
            throw new IllegalArgumentException(name);
        }
        return dimStyle;
    }

    public DxfLayer getLayer(String name) {
        DxfLayer layer = layers.get(name);
        if (layer == null) {
            throw new IllegalArgumentException(name);
        }
        return layer;
    }

    public DxfLType getLType(String name) {
        DxfLType ltype = ltypes.get(name);
        if (ltype == null) {
            throw new IllegalArgumentException(name);
        }
        return ltype;
    }

    public Object getSetting(String setting) {
        return headerSetting.get(setting);
    }

    public DxfTextStyle getTextStyle(String name) {
        DxfTextStyle textStyle = textStyles.get(name);
        if (textStyle == null) {
            throw new IllegalArgumentException(name);
        }
        return textStyle;
    }

    public Set<String> keySet() {
        return headerSetting.keySet();
    }

    public void registerClass(String appname, DxfClassDef cls) {
        List<DxfClassDef> clss = apps.get(appname);
        if (clss == null) {
            clss = new ArrayList<>();
            apps.put(appname, clss);
        }
        clss.add(cls);
    }

    public void setSetting(String setting, Object value) {
        headerSetting.put(setting, value);
    }
}
